package com.five.community.intercepetor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AdminIntercepetor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        Object admin = request.getSession().getAttribute("admin");
        if (admin == null) {
            // 重定向到登录画面
            response.sendRedirect(request.getContextPath() + "/loginUi");
            // 拦截
            return false;
        }

        // 放行
        return true;
    }
}
